<style type="text/css">
    .demo-upload-list {
        display: inline-block;
        width: 60px;
        height: 60px;
        text-align: center;
        line-height: 60px;
        border: 1px solid transparent;
        border-radius: 4px;
        overflow: hidden;
        background: #fff;
        position: relative;
        box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
        margin-right: 4px;
    }

    .demo-upload-list img {
        width: 100%;
        height: 100%;
    }

    .demo-upload-list-cover {
        display: none;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0, 0, 0, .6);
    }

    .demo-upload-list:hover .demo-upload-list-cover {
        display: block;
    }

    .demo-upload-list-cover i {
        color: #fff;
        font-size: 20px;
        cursor: pointer;
        margin: 0 2px;
    }

    .selected-search {
        border: 1px solid #dddee1;
        height: 200px;
        width: 260px;
        position: relative;
        border-radius: 4px;
    }

    .selected-search .search-action {
        position: absolute;
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .selected-search .selected-arr {
        position: absolute;
        top: 50px;
        left: 20px;
        right: 20px;
        bottom: 10px;
        overflow: scroll;
    }

    .select-click {
        border: 1px solid #dddee1;
        border-radius: 4px;
        padding: 0 10px;
        margin-bottom: 10px;
    }

    .selected-search .selected-arr .selected-item {
        /*border-bottom: 1px solid #dfdfdf;*/
    }
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
        <Form-item label="驾驶证编号" prop="licenseid">
            <i-input v-model="formValidate.licenseid" placeholder="请输入驾驶证编号"></i-input>
        </Form-item>
        <Form-item label="车辆类型" prop="alloweddrive">
            <i-select v-model="formValidate.alloweddrive" placeholder="请选择车辆类型">
                <template v-for="(item,index) in carTypeArr">
                    <i-option :value="item">{{item}}</i-option>
                </template>
            </i-select>
        </Form-item>
        <Form-item label="负责人" prop="personalName">
            <p @click="getPeopelData()" class="select-click">{{personalName}}</p>
            <div v-if="selectPeopelIsShow" class="selected-search">
                <div class="search-action">
                    <i-input placeholder="查询人姓名"></i-input>
                </div>
                <div class="selected-arr">
                    <template v-for="(item,index) in principalArr">
                        <p @click="choosePeople(item.id,item.personalname)" class="selected-item">
                            {{item.personalname}}</p>
                    </template>
                </div>
            </div>
        </Form-item>
        <Form-item label="上次驾驶审核">
            <Row>
                <i-col span="11">
                    <Date-picker type="datetime" placeholder="选择上次驾驶审核日期" @on-change="changeUpDate"></Date-picker>
                </i-col>
            </Row>
        </Form-item>
        <Form-item label="获取驾驶证">
            <Row>
                <i-col span="11">
                    <Date-picker type="datetime" placeholder="选择获取驾驶证日期" @on-change="changeGetDate"></Date-picker>
                </i-col>
            </Row>
        </Form-item>
        <Form-item label="下次驾照审核">
            <Row>
                <i-col span="11">
                    <Date-picker type="datetime" placeholder="选择下次驾照审核日期" @on-change="changeNextDate"></Date-picker>
                </i-col>
            </Row>
        </Form-item>
        <!--上传图片-->
        <upImage :upImageData="upImageData" @get-postImg-data="getImgData"></upImage>
        <upImage :upImageData="upImageData2" @get-postImg-data="getImgData2"></upImage>
        <!--<Form-item label="驾驶证正面" prop="image">-->
        <!--<div class="demo-upload-list" v-for="item in imageList">-->
        <!--<template v-if="item.status === 'finished'">-->
        <!--<img :src="apiUtilBase + item.response.Msg">-->
        <!--<div class="demo-upload-list-cover">-->
        <!--<Icon type="ios-eye-outline" @click="handleView(apiUtilBase + item.response.Msg)"></Icon>-->
        <!--<Icon type="ios-trash-outline" @click="handleRemove(item)"></Icon>-->
        <!--</div>-->
        <!--</template>-->
        <!--<template v-else>-->
        <!--<Progress v-if="item.showProgress" :percent="item.percentage" hide-info></Progress>-->
        <!--</template>-->
        <!--</div>-->
        <!--<Upload ref="upload"-->
        <!--:show-upload-list="false"-->
        <!--:default-file-list="defaultList"-->
        <!--:on-success="handleSuccess"-->
        <!--:format="['jpg','jpeg','png']"-->
        <!--:max-size="2048"-->
        <!--:name="'uploadFile'"-->
        <!--:on-format-error="handleFormatError"-->
        <!--:on-exceeded-size="handleMaxSize"-->
        <!--:before-upload="handleBeforeUpload"-->
        <!--multiplelayout-content-->
        <!--type="drag"-->
        <!--:action="upLoadFile"-->
        <!--style="display: inline-block;width:58px;">-->
        <!--<div style="width: 58px;height:58px;line-height: 58px;">-->
        <!--<Icon type="camera" size="20"></Icon>-->
        <!--</div>-->
        <!--</Upload>-->
        <!--<Modal title="查看图片" v-model="visible">-->
        <!--<img :src="seeImg" v-if="visible" style="width: 100%">-->
        <!--</Modal>-->
        <!--</Form-item>-->
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
            <i-button type="ghost" @click="backGoJump()" style="margin-left: 8px">返回</i-button>
        </Form-item>

    </i-form>

</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import upImage from '../../components/upImage';
    import baseUtil from '../../assets/utils/base-util';


    /**
     * 人员Id peopleid, 驾驶证正本照片路径 licenseimage,
     * 驾驶证副本照片路径 licenseimageb,
     * 上一次驾驶审查日期 lastcheckdate,
     * 获取驾驶证时间 firstcheckdate
     * 下一次驾照审查时间 nextcheckdate，
     * 驾驶证编号 licenseid，准驾车型 alloweddrive
     */

    export default {
        data() {
            return {
                carTypeArr: [
                    '大型汽车', '小型汽车', '专用汽车', '特种车', '电瓶车', '三轮摩托车', '二轮摩托车', '四轮农用运输车', '三轮农用运输车',
                ],
                formValidate: {
                    //添加字段
                    licenseid: '',
                    alloweddrive: '',
                    lastcheckdate: '',
                    firstcheckdate: '',
                    nextcheckdate: '',
                },
                ruleValidate: {},
                //被人员列表
                principalId: '',
                principalArr: [],
                personalName: '请选择',
                selectPeopelIsShow: false,
                //图片
                imageLicenseimage: [],
                upImageData: {
                    title: '驾驶证正面'
                },
                imageLicenseimageb: [],
                upImageData2: {
                    title: '驾驶证反面'
                }
            }
        },
        components: {
            upImage
        },
        mounted: function () {
            // this.uploadList();
        },

        methods: {
            //backJump
            backGoJump:function(){
                this.$router.back(-1)

            },
            //跳转
            jumpPage: function (id, url) {
                //跳转
                let route = '';
                if (id.length > 0) {
                    route = {
                        path: url,
                        query: {
                            id: id
                        },
                    };
                } else {
                    route = {
                        path: url,
                    };
                }

                this.$router.push(route);
            },
            getImgData: function (value) {
                console.log('图片数据：', value);
                this.imageLicenseimage =value;
            },
            getImgData2: function (value) {
                console.log('图片数据：', value);
                this.imageLicenseimageb =value;
            },
            changeUpDate: function (date) {
                console.log('date:', date)
                this.formValidate.lastcheckdate = date;
            },
            changeGetDate: function (date) {
                console.log(date);
                this.formValidate.firstcheckdate = date;

            },
            changeNextDate: function (date) {
                console.log(date);
                this.formValidate.nextcheckdate = date;

            },
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.addData(model);
                })
            },
            //获取人
            getPeopelData() {
                let that = this;

                let para = {
                    curPage: 1,
                    pageSize: '',
                };

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.userList, para, function (res) {
                    that.$Loading.finish();

                    if(that.selectPeopelIsShow){
                        that.selectPeopelIsShow =false
                    }else {
                        that.selectPeopelIsShow = true;
                    }

                    that.principalArr = res.Msg.Arrays;
                });
            },
            choosePeople: function (id, name) {
                this.principalId = id;
                this.personalName = name;
                this.selectPeopelIsShow = false;

            },
            //添加
            addData: function (model) {
                let that = this;

                console.log('this.imageLicenseimage[0]：',this.imageLicenseimage[0]);
                console.log('this.imageLicenseimageb[0]：',this.imageLicenseimageb[0]);
                model.licenseimage =this.imageLicenseimage[0].img;
                model.licenseimageb =this.imageLicenseimageb[0].img;
                model.peopleid =this.principalId;
                let params = that.$qs.stringify(model);
                this.$Loading.start();

                apiUtil.post(that, apiUtil.urls.AddDriver, params, function (res) {
                    that.$Loading.finish();

                    that.$Modal.confirm({
                        title: '操作成功',
                        content: '请选择下一步操作',
                        okText: '继续添加',
                        cancelText: '返回列表',
                        onOk: () => {
                            that.$router.go(0);
                        },
                        onCancel: () => {
                            baseUtil.pageJump(that,'','DriverList')
                        }
                    });

                });
            },

        }
    }
</script>
